package main

import "fmt"

func fibonacli(c, quit chan int){
    x, y := 1, 1

    //select具备多路channel监控状态功能
    for{
        select{
            //如果c可写
            case c <- x:
                x = y
                y = x +y
            //quit可读
            case <-quit:
                fmt.Println("quit")
                return
        }
    }

}

func main(){
    c := make(chan int)
    quit := make(chan int)

    go func(){
        for i := 0; i < 4; i++{
            fmt.Println(<-c)
        }

        quit <- 0
    }()

    fibonacli(c,quit)
}